package fr.uniscol.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;

import fr.uniscol.dao.IPeriodeDao;
import fr.uniscol.model.AnneeScolaire;
import fr.uniscol.model.Periode;

public class PeriodeDaoImpl implements IPeriodeDao {

	private SessionFactory sessionFactory;
	
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	public List<Periode> getAllPeriodes(AnneeScolaire annee) {

		Session session = sessionFactory.getCurrentSession();
		
		Query q = session.createQuery("From Periode Where annee_id=:annee_id");
		q.setParameter("annee_id", annee.getId());
		
		return q.list();
	}
	
	public void enregistrerPeriode(Periode periode) {
		
		Session session = sessionFactory.getCurrentSession();
		
		session.saveOrUpdate(periode);
	}
}
